﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Products.aspx.cs" Inherits="MobileWeb.Products"
    MasterPageFile="~/Site.Master" %>

<asp:Content runat="server" ID="cProducts" ContentPlaceHolderID="cBody">
    <ul class="entity-list items-container" id="ulProductList">
        <asp:Repeater runat="server" ID="rptProductList">
            <ItemTemplate>
                <li style="cursor: pointer;">
                    <img width="90" height="90" title="<%# Eval("Name") %>" alt="<%# Eval("Name") %>"
                        src="<%# MobileWeb.Utilities.GetKeySetting("PCHost") + "/" + MobileWeb.Utilities.GetKeySetting("PathUploadImageThumb") + "/" + Eval("ImageUrl")%>"
                        itemprop="image" />
                    <h3>
                        <a href="ProductDetail.aspx?cid=<%# Eval("CategoryID") %>&id=<%# Eval("ProductID") %>">
                            <p class="truncate">
                                <%# Eval("Name") %></p>
                        </a>
                    </h3>
                    <div>
                        <span class="price">
                            <%# Convert.IsDBNull(Eval("Price")) || Convert.ToDecimal(Eval("Price")) == Convert.ToDecimal("0") ? "" : String.Format("{0:C}",
                        Eval("Price"))%></span></div>
                </li>
            </ItemTemplate>
        </asp:Repeater>
    </ul>
    <div class="load-items">
        <a href="#" id="buttonLoadItem" rel="0|5">Load More</a>
    </div>
    <script type="text/javascript">
        $(window).ready(function(){
            function LoadProducts(pageIndex, pageSize) {
                $.get( "GetProducts.aspx", { catid: <%= CategoryID %>, page: pageIndex, size: pageSize }, function(data){
                    $("#ulProductList").append(data);
                });
                $("#buttonLoadItem").attr("rel", pageIndex + "|" + pageSize);
            }
        
            $(document).ready(function () {
                $("ul.entity-list li").live("click", function(){
                    var href = $(this).find("a").attr("href");
                    window.location.href = href;
                });
                $("#buttonLoadItem").click(function(e){
                    e.preventDefault();
                    var rel = $(this).attr("rel");
                    LoadProducts(parseInt(rel.split("|")[0]) + 1, rel.split("|")[1]);
                });
            });
        });
    </script>
</asp:Content>
